package finalproject.bd1.sql.gui;

import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.SwingConstants;


public class FormEmployeeGUI extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private JPanel contentPane;
	private JTextField nameField;
	private JTextField cpfField;
	private JTextField phoneField1;
	private JTextField phoneField2;
	private JLabel lblEndereo;
	private JTextField streetField;
	private JTextField neighborhoodField;
	private JTextField cityField;
	private JLabel lblCadastroDeClientes;
	private JTextField codeField;
	private JTextField positionField;
	private JTextField cepField;
	private JLabel lblCep;
	private JLabel label;
	private JTextField ufField;
	private JTextField AdmissionField;
	private JLabel lblDataAdmisso;
	private JTextField resignationField;
	private JLabel lblDataDemisso;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater( new Runnable() {
			public void run() {
				try {
					FormEmployeeGUI frame = new FormEmployeeGUI();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public FormEmployeeGUI() {
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 449, 385);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		setTitle("Cadastro de funcion\u00E1rios");
		setLocationRelativeTo(null);
		contentPane.setLayout(null);
		
		fieldsForm(); //Call all itens form.

		buttons(); //Call buttons to write data.
	}

	/**
	 * Call all itens form.
	 */
	private void fieldsForm() {
		lblCadastroDeClientes = new JLabel("Cadastro de funcion\u00E1rios");
		lblCadastroDeClientes.setHorizontalAlignment(SwingConstants.CENTER);
		lblCadastroDeClientes.setFont(new Font("Times New Roman", Font.BOLD, 18));
		lblCadastroDeClientes.setBounds(118, 21, 196, 14);
		contentPane.add(lblCadastroDeClientes);
		
		JLabel lblNome = new JLabel("Nome: ");
		lblNome.setBounds(10, 64, 49, 14);
		contentPane.add(lblNome);
		
		nameField = new JTextField();
		nameField.setBounds(70, 61, 354, 20);
		contentPane.add(nameField);
		nameField.setColumns(10);
		setName(nameField.getText());
		
		JLabel lblCode = new JLabel("Matr\u00EDcula: ");
		lblCode.setBounds(10, 92, 59, 14);
		contentPane.add(lblCode);
		
		codeField = new JTextField();
		codeField.setColumns(10);
		codeField.setBounds(70, 89, 143, 20);
		contentPane.add(codeField);
		
		JLabel lblCpf = new JLabel("CPF: ");
		lblCpf.setBounds(221, 92, 34, 14);
		contentPane.add(lblCpf);
		
		cpfField = new JTextField();
		cpfField.setBounds(250, 89, 174, 20);
		contentPane.add(cpfField);
		cpfField.setColumns(10);
		
		JLabel lblTelefone1 = new JLabel("Phone1");
		lblTelefone1.setBounds(10, 124, 59, 14);
		contentPane.add(lblTelefone1);
		
		phoneField1 = new JTextField();
		phoneField1.setBounds(70, 120, 143, 20);
		contentPane.add(phoneField1);
		phoneField1.setColumns(10);
		
		JLabel lblTelefone2 = new JLabel("Phone2");
		lblTelefone2.setBounds(223, 124, 59, 14);
		contentPane.add(lblTelefone2);
		
		phoneField2 = new JTextField();
		phoneField2.setColumns(10);
		phoneField2.setBounds(280, 120, 143, 20);
		contentPane.add(phoneField2);
		
		lblEndereo = new JLabel("Rua: ");
		lblEndereo.setBounds(10, 154, 46, 14);
		contentPane.add(lblEndereo);
		
		streetField = new JTextField();
		streetField.setBounds(70, 151, 354, 20);
		contentPane.add(streetField);
		streetField.setColumns(10);
		
		JLabel lblBairro = new JLabel("Bairro: ");
		lblBairro.setBounds(10, 182, 46, 14);
		contentPane.add(lblBairro);
		
		neighborhoodField = new JTextField();
		neighborhoodField.setBounds(70, 179, 244, 20);
		contentPane.add(neighborhoodField);
		neighborhoodField.setColumns(10);
		
		label = new JLabel("UF: ");
		label.setBounds(335, 182, 28, 14);
		contentPane.add(label);
		
		ufField = new JTextField();
		ufField.setColumns(10);
		ufField.setBounds(365, 179, 59, 20);
		contentPane.add(ufField);
		
		JLabel lblCidade = new JLabel("Cidade: ");
		lblCidade.setBounds(10, 213, 46, 14);
		contentPane.add(lblCidade);
		
		cityField = new JTextField();
		cityField.setBounds(70, 210, 185, 20);
		contentPane.add(cityField);
		cityField.setColumns(10);
		
		lblCep = new JLabel("CEP: ");
		lblCep.setBounds(268, 213, 46, 14);
		contentPane.add(lblCep);
		
		cepField = new JTextField();
		cepField.setColumns(10);
		cepField.setBounds(308, 210, 116, 20);
		contentPane.add(cepField);
		
		JLabel lblCargo = new JLabel("Cargo: ");
		lblCargo.setBounds(10, 240, 46, 14);
		contentPane.add(lblCargo);
		
		positionField = new JTextField();
		positionField.setColumns(10);
		positionField.setBounds(70, 240, 354, 20);
		contentPane.add(positionField);
		
		lblDataAdmisso = new JLabel("Admiss\u00E3o: ");
		lblDataAdmisso.setBounds(10, 274, 71, 14);
		contentPane.add(lblDataAdmisso);
		
		AdmissionField = new JTextField();
		AdmissionField.setColumns(10);
		AdmissionField.setBounds(70, 271, 143, 20);
		contentPane.add(AdmissionField);
		
		lblDataDemisso = new JLabel("Demiss\u00E3o: ");
		lblDataDemisso.setBounds(221, 274, 71, 14);
		contentPane.add(lblDataDemisso);
		
		resignationField = new JTextField();
		resignationField.setColumns(10);
		resignationField.setBounds(281, 271, 143, 20);
		contentPane.add(resignationField);
	}
	
	/**
	 * Call buttons to write data.
	 */
	private void buttons() {
		JButton btnCadastraCliente = new JButton("Cadastrar");
		btnCadastraCliente.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				JOptionPane.showMessageDialog(null, nameField.getText());
			}
		});
		btnCadastraCliente.setForeground(Color.BLACK);
		btnCadastraCliente.setBounds(158, 313, 117, 23);
		contentPane.add(btnCadastraCliente);

		JButton btnCancelar = new JButton("Limpar");
		btnCancelar.addActionListener(new ActionListener() {
			/**
			 * Clean all fields in frame
			 * @author Grinvon
			 * @link http://www.guj.com.br/java/32502-limpando-todos-os-campos-jtextfield#174173
			 */
			public void actionPerformed(ActionEvent event) {
				for (int i=0; i < getContentPane().getComponentCount(); i++) {
					//Mapping each component on Jframe.
					Component c = getContentPane().getComponent(i);
					if (c instanceof JTextField) {
						JTextField field = (JTextField) c;
						field.setText("");
						System.out.println("Cleaning field " + i);
					}
				}
			}
		});
		btnCancelar.setForeground(Color.BLACK);
		btnCancelar.setBounds(337, 313, 86, 23);
		contentPane.add(btnCancelar);
	}
	
}
